package com.ctg.itrdc.imageconsole.control.sys;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ctg.itrdc.imageconsole.common.bean.CommonResult;
import com.ctg.itrdc.imageconsole.common.bean.ReturnCodeDefine;
import com.ctg.itrdc.imageconsole.data.entity.SystemNotice;
import com.ctg.itrdc.imageconsole.service.ISystemNoticeService;
import com.ctg.itrdc.pasp.security.utils.WebUtils;
import com.ctg.itrdc.paspsdk.common.entity.PageInfo;

/**
 * 系统通知接口
 * @Description 
 * @author wupiao
 * @since 2017年2月24日
 */
@Controller
@RequestMapping("/systemNotice")
public class SystemNoticeController {

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Resource
	private ISystemNoticeService systemNoticeService;

	
	@RequestMapping(value = "/queryNoticeList", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult queryNoticeList(@RequestParam(value = "noticeType", required = false) String noticeType,
			@RequestParam(value = "noticeContent", required = false) String noticeContent,
			@RequestParam(value = "noticeState", required = false) String noticeState,
			@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
		try {
			SystemNotice notice = new SystemNotice();
			notice.setNoticeContent(noticeContent);
			notice.setNoticeType(noticeType);
			notice.setNoticeState(noticeState);
			notice.setNoticeUserId(WebUtils.getCtgUser().getSysUserId());
			PageInfo<SystemNotice> pageInfo = systemNoticeService.queryNoticePageList(notice, pageNum, pageSize);
			if (pageInfo.getList().size() > 0) {
				return new CommonResult(ReturnCodeDefine.Code.C1000, ReturnCodeDefine.Msg.M1000, pageInfo);
			}
			PageInfo<SystemNotice> pageInfoForNull = new PageInfo<>();
			pageInfoForNull.setList(new ArrayList<SystemNotice>());

			return new CommonResult(ReturnCodeDefine.Code.C1000, ReturnCodeDefine.Msg.M1000, pageInfoForNull);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return new CommonResult(ReturnCodeDefine.Code.C1200, e.getMessage());
		}
	}


	@RequestMapping(value = "/queryNoticeDetail", method = RequestMethod.GET)
	@ResponseBody
	public CommonResult queryNoticeDetail(@RequestParam Long id) {
		try {
			SystemNotice systemNotice = new SystemNotice();
			systemNotice.setId(id);
			systemNotice = systemNoticeService.queryNoticeDetail(systemNotice);
			return new CommonResult(ReturnCodeDefine.Code.C1000, ReturnCodeDefine.Msg.M1000, systemNotice);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return new CommonResult(ReturnCodeDefine.Code.C1200, e.getMessage());
		}
	}
	
	@RequestMapping(value = "/modifyNotice", method = RequestMethod.POST)
	@ResponseBody
	public CommonResult modifyNotice(@RequestBody SystemNotice systemNotice) {
		try {
			systemNoticeService.modifyNotice(systemNotice);
			return new CommonResult(ReturnCodeDefine.Code.C1000, ReturnCodeDefine.Msg.M1000);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return new CommonResult(ReturnCodeDefine.Code.C1200, e.getMessage());
		}
	}

}
